/*
 * @Author: 生俊甫 1758142861@qq.com
 * @Date: 2024-11-03 15:58:04
 * @LastEditors: 生俊甫 1758142861@qq.com
 * @LastEditTime: 2024-11-03 15:59:35
 * @FilePath: /sjf/2024-project/2024_centos/test_to_c/408_str/2017.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>

typedef char BTNDataType;

typedef struct node
{
    char data;
    BTNode* left;
    BTNode* right;
}BTNode;
/**
 * 本质上是再中序遍历上对每个节点添加括号
 * 然后再对冗余的括号进行处理
 * 最后得到表达式
 */
void bnode_to_exp(BTNode* root,int level)
{
    if(root != NULL)
    {
        if(root->left == NULL && root->right == NULL)
            printf("%s ",root->data);
        else
        {
            if(level > 0)
                printf("(");
            bnode_to_exp(root->left,level+1);
            printf("%s ",root->data);
            bnode_to_exp(root->right,level+1);
            if(level > 0)
                printf(")");
        }
    }
}